{extend name="base"/}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
             <div id="tab_demo" class="HuiTab" style="margin-bottom: 15px; position:relative;">
                        <div class="tabBar clearfix">
                            <span class="current">文章列表</span>
                            <span onclick="window.location.href='__CONF_SITE__admin/article/article_class'">文章分类</span>
<div onclick="window.location.href='__CONF_SITE__admin/article/add_article'"  class="n_tab_add"><i class="Hui-iconfont">&#xe600;</i>添加文章</div>
                        </div>
                    </div>
        <div>
            <div class="cl pd-5 bg-1 bk-gray mt-20">
                <form class="Huiform" method="post" action="__CONF_SITE__admin/Article/article_list" style=" padding: 15px;">
                    <div class="text-c">
                        文章类型：
                        <span class="select-box" style="width: auto;">
                          <select class="select" size="1" name="class_name">
                                 <option {if condition="$class_name==0"} selected {/if} value="0">全部</option>
                              {volist name="a_list" id="cl"}
                            <option {if condition="$cl.class_id==$class_name"} selected {/if} value="{$cl['class_id']}">{$cl['name']}</option>
                              {/volist}
                          </select>
                        </span>
                        <button class="btn btn-search radius" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜文章</button>
                    </div>
                </form>
            </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                    <thead>
                    <tr class="text-c">
                        <th>封面图</th>
                        <th>文章标题</th>
                        <th>文章短标题</th>
                        <th>作者</th>
                        <th>直接链接</th>
                        <th>所属分类</th>
                        <th>推荐</th>
                        <th>显示/隐藏</th>
                        <th>发布时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="tbody">
                    {volist name="list" id="r" key='k'}
                    <tr class="text-c va-m">
                        <td><img width="60" height="60" class="product-thumb" src="{$r['image']}"></td>
                        <td>{$r['title']|subtext=10}</td>
                        <td>{$r['short_title']|subtext=10}</td>
                        <td>{$r['author']}</td>
                        <td>
                            {if $r['link']!=''}
                            <a style="color: #0c52a6" target="_blank" href="{$r['link']}">{$r.link|subtext=20}</a>
                            {else}
                            <a href="javascript:;">无</a>
                            {/if}
                        </td>
                        <td>{$r['class_name']}</td>
                        <td>
                            {if $r['is_recommend']==0}
                            <span class="label label-default radius">无</span>
                            {/if}
                            {if $r['is_recommend']==1}
                            <span class="label label-secondary radius">推荐</span>
                            {/if}
                        </td>
                        <td>
                            {if $r['type']==1}
                            <span class="label label-success radius">显示中</span>
                            {/if}
                            {if $r['type']==2}
                            <span class="label label-warning radius	">隐藏中</span>
                            {/if}
                        </td>
                        <td>{$r['create_time']|date="Y-m-d H:i:s",###}</td>
                        <td>
                            {if $r['type']==2}
                            <a style="text-decoration:none;color:#0066cc;" title="显示" onclick="article_type('{$r.article_id}','1')" >显示</a>
                            {else}
                            <a style="text-decoration:none;color:#0066cc;" title="隐藏" onclick="article_type('{$r.article_id}','2')"  type="button" value="隐藏">隐藏</a>
                            {/if}
                            <a style="text-decoration:none;color:#0066cc;" title="编辑" href="{:url('admin/article/edit_article')}&article_id={$r.article_id}">编辑</a>
                             <a style="text-decoration:none;color:#0066cc;" title="编辑" href="javascript:void(0);" onclick="article_del(this,'{$r.article_id}')"  type="button" value="删除">删除</a>
                            <a style="text-decoration:none;color:#0066cc;" title="复制" href="javascript:void(0);" onclick="copy_now('wxpath{$k}')" id="wxpath{$k}" data-clipboard-text="yb_shop/pages/find_info/index?id={$r['article_id']}">复制链接</a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
                <div class="n_page_no">
                    {$page}
                </div>
            </div>
        </div>
        {/block}
        {block name="script"}
        <script type="text/javascript">
            /*文章-编辑*/
            function article_edit(title,url,w,h){
                layer.open({
                    type: 2,
                    area: ['800px', '600px'],
                    fix: false, //不固定
                    maxmin: true,
                    shade:0.4,
                    title: title,
                    content: url,
                    scrollbar:false
                });
            }
            /*文章-删除*/
            function article_del(obj,id){
                layer.confirm('确认要删除吗？',function(index){
                    //后台处理
                    $.ajax({
                        type : "post",
                        url : "{:url('admin/article/del_article')}",
                        data : {
                            "article_id" : id.toString(),
                        },
                        success : function(data) {
                            if (data['code'] >0) {
                                $(obj).parents("tr").remove();
                                layer.msg('删除成功!',{icon:1,time:1000});
                            }
                            else
                            {
                                layer.msg('删除失败', {icon: 2, time: 1000});
                            }
                        }
                    })
                });
            }
            function article_type(id,type) {
                var msg='';
                if (type==1){
                    msg='确定要显示文章吗？';
                }else {
                    msg='确定要隐藏文章吗？';
                }
                layer.confirm(msg,function(index){
                    $.ajax({
                        type : "post",
                        url : "__CONF_SITE__admin/article/article_type",
                        data : {'id':id,'type':type},
                        success : function(data) {
                            console.log(data);
                            if(data['code']>0 ){
                                layer.msg('成功',{icon:1,time:1000},function () {
                                    location.reload();
                                });
                            }else{
                                layer.msg('失败',{icon:5,time:1000});
                            }
                        }
                    });
                })
            }
            function copy_now(id) {
                id='#'+id;
                var check=$(id).attr('data-clipboard-text');
                if(check.length<=0){
                    layer.msg("链接信息有误", {icon: 2, time: 1000});
                    return false;
                }
                var clipboard=new Clipboard(id);
                clipboard.on('success',function(e){
                    layer.msg("链接复制成功", {icon: 1, time: 500});
                });
                clipboard.on('error', function(e) {
                    layer.msg("链接信息有误", {icon: 2, time: 1000});
                });
            }
        </script>
        {/block}